package cn.hxth.cloud.provider.handler;

import cn.hxth.cloud.api.domain.ProductionOrder;

/**
 * 采购入库单处理handler的抽象基类
 * @author zhonghuashishan
 *
 */
public abstract class AbstractProductionHandler implements ProductionHandler {


	protected ProductionHandler successor;
	protected ProductionHandlerResult result ;

	public AbstractProductionHandler() {
		this.setResult(new ProductionHandlerResult(false,false));
	}

	public ProductionHandlerResult getResult() {
		return result;
	}

	public void setResult(ProductionHandlerResult result) {
		this.result = result;
	}

	public Boolean execute(ProductionOrder productionOrder) throws Exception {
		if(!result.getResult()){
			this.setResult(doExecute(productionOrder)) ;
		}
		if(successor != null && result.getDoNext()) { 
			return successor.execute(productionOrder);
		} else {
			return result.getResult();
		}
	}
	

	protected abstract ProductionHandlerResult doExecute(
			ProductionOrder productionOrder) throws Exception;

	public ProductionHandler getSuccessor() {
		return successor;
	}

	public void setSuccessor(ProductionHandler successor) {
		this.successor = successor;
	}
	
}
